home *** CD-ROM | disk | FTP | other *** search
/ SPACE 1 / SPACE - Library 1 - Volume 1.iso / program / 441 / dlibs12 / stradj.c < prev    next >
Text File  |  1990-11-23  |  880b  |  39 lines

  1. char *stradj(string, dir)
  2.     register char *string;
  3.     register int dir;
  4. /*
  5.  *    Adjust <string> by adding space if <dir> is positive, or removing
  6.  *    space if <dir> is negative.  The magnitude of <dir> is the number
  7.  *    of character positions to add or remove.  Characters are added or
  8.  *    removed at the beginning of <string>.  A pointer to the modified
  9.  *    <string> is returned.
  10.  */
  11.     {
  12.     register char *p = string, *q;
  13.  
  14.     if(dir == 0)
  15.         return(string);
  16.     if(dir > 0)            /* add space */
  17.         {
  18.         while(*p)            /* find end */
  19.             ++p;
  20.         q = p + dir;            /* set gap */
  21.         while(p >= string)        /* copy data */
  22.             *q-- = *p--;
  23.         while(q >= string)        /* replace <nul>s */
  24.             {
  25.             if(*q == '\0')
  26.                 *q = ' ';
  27.             --q;
  28.             }
  29.         }
  30.     else                /* remove space */
  31.         {
  32.         dir = -dir;
  33.         q = p + dir;            /* set gap */
  34.         while(*p++ = *q++)        /* copy data */
  35.             ;
  36.         }
  37.     return(string);
  38.     }
  39.